package mq

import (
	"gitee.com/vrv_media/go-micro-framework/pkg/errors"
	"github.com/spf13/pflag"
)

type MqOptions struct {
	Addrs     []string `mapstructure:"addr"       json:"addr,omitempty"`
	GroupName string   `mapstructure:"group-name" json:"group-name,omitempty"`
	Topic     string   `mapstructure:"topic" json:"topic,omitempty"`
	Retry     int      `mapstructure:"retry"      json:"retry,omitempty"`
}

func NewRocketmqOptions() *MqOptions {
	return &MqOptions{
		Addrs:     []string{"127.0.0.1:9876"},
		GroupName: "default",
		Topic:     "",
		Retry:     3,
	}
}

func (o *MqOptions) AddFlags(fs *pflag.FlagSet) {
	fs.StringArrayVar(&o.Addrs, "mq.address", o.Addrs, "mq address .")
	fs.StringVar(&o.GroupName, "mq.group-name", o.GroupName, "mq group name.")
	fs.StringVar(&o.Topic, "mq.topic", o.Topic, "mq topic.")
	fs.IntVar(&o.Retry, "mq.retry", o.Retry, "mq retry count.")

}

func (o *MqOptions) Validate() error {
	if len(o.Addrs) == 0 {
		return errors.New("addrs is empty")
	}
	if o.GroupName == "" {
		return errors.New("group-name is empty")
	}
	return nil
}
